package com.wavehi.consumer;

import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.wavehi.util.RabbitMQFactoryUtils;
import net.bytebuddy.implementation.bind.annotation.DefaultCall;

import java.io.IOException;

/**
 * @Description 消费者
 * @Author WaveHi
 * @Date 24/12/2021 下午 3:42
 * @Version 1.0
 * @Contact HJBWaveHi@163.com
 */
public class Consumer_01 {

    private final static String QUEUE_NAME = "Hello";

    public static void main(String[] args) throws Exception {

        //1.获取信道
        Channel channel = RabbitMQFactoryUtils.getChannel();
        //2.接收消息
        DeliverCallback deliverCallback = (consumerTag, message) -> {
            System.out.println("Message : " + new String(message.getBody()));
        };
        CancelCallback cancelCallback = consumerTag -> {
            System.out.println("Message getting stop ！");
        };
        System.out.println("Consumer_01 waits for message...");
        channel.basicConsume(QUEUE_NAME, true, deliverCallback, cancelCallback);

    }
}
